//
//  VisitorLoginIn.swift
//  新浪微博(Swift)
//
//  Created by MichaelLi on 16/8/16.
//  Copyright © 2016年 lihonggui. All rights reserved.
//

import UIKit

class VisitorLoginIn: UIView {

    /*
     重写构造方法
     */
    init() {
        super.init(frame: CGRectZero)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置访客视图
    private func setupUI()
    {
        backgroundColor = UIColor(white: 0.93, alpha: 1)
        //测试,没登录启动画面是红色
        //backgroundColor = UIColor.redColor()
        //添加所有控件
        addSubview(circelViewImage)
        addSubview(houseViewImage)
        addSubview(labelText)
        addSubview(loginButton)
        addSubview(registerButton)
        addSubview(backViewImage)
        //设置 frame 布局失效
        circelViewImage.translatesAutoresizingMaskIntoConstraints = false
        houseViewImage.translatesAutoresizingMaskIntoConstraints  = false
        labelText.translatesAutoresizingMaskIntoConstraints       = false
        loginButton.translatesAutoresizingMaskIntoConstraints     = false
        registerButton.translatesAutoresizingMaskIntoConstraints  = false
        backViewImage.translatesAutoresizingMaskIntoConstraints = false
        /*------设置线性约束------*/
       /* item: <#T##AnyObject#>--->约束谁
         attribute: <#T##NSLayoutAttribute#>--->位置
         relatedBy: <#T##NSLayoutRelation#>--->大小
         toItem: <#T##AnyObject?#>--->以谁为约束
         multiplier: <#T##CGFloat#>--->乘数
         constant: <#T##CGFloat#>---?--->系数

        addConstraint(NSLayoutConstraint(item: <#T##AnyObject#>, attribute: <#T##NSLayoutAttribute#>, relatedBy: <#T##NSLayoutRelation#>, toItem: <#T##AnyObject?#>, attribute: <#T##NSLayoutAttribute#>, multiplier: <#T##CGFloat#>, constant: <#T##CGFloat#>))
       */
        //VFL
        //设置滚动图片约束布局
        addConstraint( NSLayoutConstraint(item:circelViewImage, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: circelViewImage, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1.0, constant: -60))

        //设置小房子图片约束布局
       addConstraint(NSLayoutConstraint(item:houseViewImage, attribute: .CenterX, relatedBy: .Equal, toItem: circelViewImage, attribute: .CenterX, multiplier:1.0, constant:0))
       addConstraint(NSLayoutConstraint(item:houseViewImage, attribute: .CenterY, relatedBy: .Equal, toItem: circelViewImage, attribute: .CenterY, multiplier:1.0, constant:0))

        //设置文本约束布局
         addConstraint(NSLayoutConstraint(item:labelText, attribute: .CenterX, relatedBy: .Equal, toItem: circelViewImage, attribute: .CenterX, multiplier:1.0, constant:0))
        addConstraint(NSLayoutConstraint(item:labelText, attribute: .Top, relatedBy: .Equal, toItem: circelViewImage, attribute: .Bottom, multiplier:1.0, constant:0))
         addConstraint(NSLayoutConstraint(item:labelText, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier:1.0, constant:200))

        //设置注册按钮的约束布局
        addConstraint(NSLayoutConstraint(item:loginButton, attribute: .Top, relatedBy: .Equal, toItem: labelText, attribute: .Bottom, multiplier:1.0,            constant:0))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .Left, relatedBy: .Equal, toItem: labelText, attribute: .Left, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item:loginButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier:1.0,        constant:80))
        addConstraint(NSLayoutConstraint(item:loginButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier:1.0,        constant:25))

        //设置登录按钮的约束布局
       addConstraint(NSLayoutConstraint(item:registerButton, attribute: .Top, relatedBy: .Equal, toItem: labelText, attribute: .Bottom, multiplier:1.0,            constant:0))
       addConstraint(NSLayoutConstraint(item: registerButton, attribute: .Right, relatedBy: .Equal, toItem: labelText, attribute: .Right, multiplier: 1, constant: 0))
       addConstraint(NSLayoutConstraint(item:registerButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier:1.0,        constant:80))
       addConstraint(NSLayoutConstraint(item:registerButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier:1.0,constant:25))

        //设置背景图片约束布局
       addConstraint(NSLayoutConstraint(item: backViewImage, attribute: .CenterX, relatedBy: .Equal, toItem:self, attribute: .CenterX, multiplier: 1, constant: 0))
       addConstraint(NSLayoutConstraint(item: backViewImage, attribute: .CenterY, relatedBy: .Equal, toItem:circelViewImage, attribute: .CenterY, multiplier: 1, constant: 0))
       addConstraint(NSLayoutConstraint(item:backViewImage, attribute: .Width, relatedBy: .Equal, toItem: self, attribute: .Width, multiplier:1.0,constant:0))
       addConstraint(NSLayoutConstraint(item:backViewImage, attribute: .Height, relatedBy: .Equal, toItem: circelViewImage, attribute: .Height, multiplier:1.0,constant:0))

    }

    /*------懒加载所有控件------*/

    //加载滚动的图片
    private lazy var circelViewImage :UIImageView = UIImageView(image: UIImage(named:"visitordiscover_feed_image_smallicon"))
    //加载小房子图片
    private lazy var houseViewImage :UIImageView = UIImageView(image: UIImage(named:"visitordiscover_feed_image_house"))
    //加载背景图片
    private lazy var backViewImage :UIImageView = UIImageView(image: UIImage(named:"visitordiscover_feed_mask_smallicon"))
    //加载文本
    private lazy var labelText :UILabel =
        {
        //实例化
        let l           = UILabel()
        l.text          = "关注一些人，回这里看看有什么惊喜。"
        //位置
        l.textAlignment = NSTextAlignment.Center
        //字体大小
        l.font          = UIFont.systemFontOfSize(14)
        //颜色
        l.textColor     = UIColor.lightGrayColor()
        //换行
        l.numberOfLines = 0
        //自动适应
        l.sizeToFit()
        return l
    }()
    //加载注册按钮
    private lazy var loginButton :UIButton =
    {
        let btn = UIButton()

        btn.setTitle("注册", forState: .Normal)
    btn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: .Normal)
        btn.setTitleColor(UIColor.lightGrayColor(), forState: .Normal)
        return btn
    }()
    //加载登录按钮
    private lazy var registerButton :UIButton =
        {
            let btn = UIButton()
            btn.setTitle("登录", forState: .Normal)
        btn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: .Normal)
            btn.setTitleColor(UIColor.orangeColor(), forState: .Normal)
            return btn
    }()



}
